package com.controller;

import com.dto.AddPostingInfoDTO;
import com.entity.PostingInfo;
import com.service.PostingInfoService;
import com.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帖子的控制器
 *
 * @author lbb
 * @version 1.0
 * @date 2020.3.1
 */
@RestController
@RequestMapping("/api")
public class PostingInfoController {
	
	@Autowired
	private PostingInfoService postingInfoService;
	
	/**
	 * 发表帖子
	 *
	 * @return
	 */
	@PostMapping("/postingInfo/add")
	public ResponseVO addPostingInfo(@RequestBody AddPostingInfoDTO addPostingInfoDTO) {
		Boolean bool = postingInfoService.addPostingInfo(addPostingInfoDTO.getPostingInfo(),addPostingInfoDTO.getUserIds());
		ResponseVO vo = new ResponseVO();
		if (bool) {
			vo.setCode("200");
			vo.setMsg("发布成功！");
		} else {
			vo.setCode("500");
			vo.setMsg("发布失败！");
		}
		return vo;
	}

	/**
	 * 查看说说
	 * @param userId
	 * @param isAddBrowseCount 是否添加浏览次数
	 * @return
	 */
	@GetMapping("/postingInfo/query")
	public ResponseVO getUserCanSeePostingInfo(Integer userId,Integer isAddBrowseCount) {
		List<PostingInfo> postingInfoList = postingInfoService.getUserCanSeePostingInfo(userId,isAddBrowseCount);
		ResponseVO vo = new ResponseVO();
		vo.setCode("200");
		vo.setData(postingInfoList);
		return vo;
	}
	
	/**
	 * 删除帖子
	 *
	 * @param postingId 帖子ID
	 * @param userId 用户ID
	 * @return
	 */
	@DeleteMapping("/postingInfo/del")
	public ResponseVO delPostingInfo(Integer postingId, Integer userId) {
		Boolean bool = postingInfoService.delPostingInfo(postingId,userId);
		ResponseVO vo = new ResponseVO();
		if (bool) {
			vo.setCode("200");
			vo.setMsg("删除成功！");
		} else {
			vo.setCode("500");
			vo.setMsg("删除失败！");
		}
		vo.setData(bool);
		return vo;
	}
}
